/**
 * 功能描述
 */

define(function (require, exports, module) {
	var aw = require("ajaxwrapper");
	var store =require("store");
	var activeUser = store.get("user");
	var Dialog = require("dialog");
	var activeUser = store.get("user");
	var roles = activeUser.roles;
	var enmu = require("enums");
	var Form = require("form");
	var _=require("underscore");
	
	var role = activeUser.roles;
	
    module.exports = {
    	betch:function(widget,betch,data){

			
			/*Clear("净房"), 
			Drity("脏房"),
			CheckIn("在住房"),
			WillGo("将走房"),
			Appoint("预订"),
			Repairing("维修房"),
			Temporary("临时态"),
			SelfUse("自用房"),
			Free("免费房");*/
			var items;
			var status= enmu["com.eling.elcms.basedoc.model.Room.Status"];        						
			if(widget.get("type")=="vestibule"){//前厅
				items=["Dirty","Clear","Temporary","SelfUse","Free"];
			}else{
				items=["Dirty","Clear","Temporary","Repairing"];
			}
			var item=[];
			for(var i=0;i<status.length;i++){
				for(var j=0;j<items.length;j++){
					if(status[i].key==items[j]){
						item.push(status[i]);
						break;
					}
				}
			}
			//服务点管理
//			var ZClear = ["Repairing","Temporary","SelfUse","Free"];
//			var ZDrity = ["Clear","Repairing","Temporary","SelfUse","Free"];
//			var ZCheckIn = [];
//			var ZWillGo = [];
//			var ZAppoint = [];
//			var ZRepairing = ["Dirty","Clear","Temporary","SelfUse","Free"];
//			var ZTemporary = ["Dirty","Clear","Repairing","SelfUse","Free"];
//			var ZSelfUse = ["Drity","Clear","Repairing","Temporary","Free"];
//			var ZFree = ["Dirty","Clear","Repairing","Temporary","SelfUse"];
//			
//			
//			//房务中心
//			var FClear = ["Dirty","Repairing","Temporary"];
//			var FDrity = ["Clear","Repairing","Temporary"];
//			var FRepairing = ["Dirty","Clear","Temporary"];
//			var FTemporary = ["Dirty","Clear","Repairing"];
//			
//			//楼宇前台
//			var QTemporary = [];
//			var QSelfUse = ["Dirty","Clear","Repairing","Temporary","Free"];
//			var QFree = ["Dirty","Clear","Repairing","Temporary","SelfUse"];
//			
//
//			var itemsObj = {};
//			for (var i = 0; i < items.length; i++) {
//				itemsObj[items[i].key] = items[i];
//			}
//			
//			
//			var tArr = [];
//			var rooms =betch?(widget.get("grid").getSelectedData()||[]):[data];
//			var  roompks=[];
//			for ( var j in rooms) {
//				var room =rooms[j];
//				roompks.push(room.pkRoom);
//				var tmpstatus = []
//				for (var i = 0; i < roles.length; i++) {
//					//主管权限
//					if (roles[i].pkRole == 10) {
//						if(room.status.key=="Clear"){
//							tmpstatus = tmpstatus.concat(ZClear);
//						}
//						if(room.status.key=="Dirty"){
//							tmpstatus = tmpstatus.concat(ZDrity);
//						}
//						if(room.status.key=="CheckIn"){
//							tmpstatus = tmpstatus.concat(ZCheckIn);
//						}
//						if(room.status.key=="WillGo"){
//							tmpstatus= tmpstatus.concat(ZWillGo);
//						}
//						if(room.status.key=="Appoint"){
//							tmpstatus= tmpstatus.concat(ZAppoint);
//						}
//						if(room.status.key=="Repairing"){
//							tmpstatus= tmpstatus.concat(ZRepairing);
//						}
//						if(room.status.key=="Temporary"){
//							tmpstatus= tmpstatus.concat(ZTemporary);
//						}
//						if(room.status.key=="SelfUse"){
//							tmpstatus= tmpstatus.concat(ZSelfUse);
//						}
//						if(room.status.key=="Free"){
//							tmpstatus= tmpstatus.concat(ZFree);
//						}
//					}
//					//房务中心权限
//					if (roles[i].pkRole == 45) {
//						if(room.status.key=="Clear"){
//							tmpstatus= tmpstatus.concat(FClear);
//						}
//						if(room.status.key=="Drity"){
//							tmpstatus= tmpstatus.concat(FDrity);
//						}
//						if(room.status.key=="Repairing"){
//							tmpstatus= tmpstatus.concat(FRepairing);
//						}
//						if(room.status.key=="Temporary"){
//							tmpstatus= tmpstatus.concat(FTemporary);
//						}
//						
//					}
//					//当角色为前台时的权限
//					if (roles[i].pkRole == 40) {
//						if(room.status.key=="Temporary"){
//							tmpstatus= tmpstatus.concat(QTemporary);
//						}
//						if(room.status.key=="SelfUse"){
//							tmpstatus= tmpstatus.concat(QSelfUse)
//						}
//						if(room.status.key=="Free"){
//							tmpstatus= tmpstatus.concat(QFree)
//						}
//					}
//				}
//				if(Number(j)==0){
//					tArr=tArr.concat(tmpstatus)
//				}else{
//					//取交集
//					tArr=_.intersection(tArr,tmpstatus);
//				}
//			}
//			
//			var tItems = [];
//			for (var i = 0; i < tArr.length; i++) {
//				tItems.push(itemsObj[tArr[i]]);
//			}
					
			var remarkForm = new Form({
				parentNode:".J-dialog-conponent",
				autoRender:false,
				model:{
					defaultButton:false,
						items: [{
				            name: "status",
				            type: "select",
				            validate:"required",
				            label: "请选房态",			                							           
				            options:item,
				            style:{
				            	value:"width:75%"
				            }
				  		}]
					}	       			            	
			});
			widget.set("remarkForm",remarkForm);
			var dialog=Dialog.showComponent(remarkForm,{
				defaultButton:false,
				title:"修改房间状态",
				setStyle: function(){
					$(".modal").css({
						"width":"550px"
					});
				},
				buttons:[{
					id:"save",
					text:"保存",
					className:"btn-primary",
					handler:function(){
						if(remarkForm.valid()){
							var FormData = remarkForm.getData();
							var saveData ={};
							saveData.status = FormData.status;
							if(betch){
								saveData.pks=roompks.toString();
								saveData.status = FormData.status;
							}else{
								saveData=data;
								saveData.status = FormData.status;
								saveData.orientation = data.orientation.key;
							}
							Dialog.loading(true);
							aw.saveOrUpdate(betch?"api/room/savebetch":"api/room/save",aw.customParam(saveData),function(saveData){
								Dialog.loading(false);
								Dialog.close();
								widget.get("grid").refresh();
							},function(){
								Dialog.loading(false);
							})	
						};
					}
				},{
					id:"close",
					text:"取消",
					handler:function(){
						Dialog.close();
					}
				}]
				
			})        					     			
    		
    	}
    };
});
